package com.xwltz.rbac.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.xwltz.core.defines.Api;
import com.xwltz.core.domain.SimpleActionResult;
import com.xwltz.rbac.model.request.LoginRequest;
import com.xwltz.rbac.model.request.MemberRequest;
import com.xwltz.rbac.service.MemberService;
import com.xwltz.web.controller.BaseController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @description MemberController
 * @information on version 1.0 be created by @xwltz at 2022/1/15 17:16
 */

@RestController
@Api(path = "/member", name = "人员管理")
public class MemberController extends BaseController {

	@Resource
	private MemberService memberService;

	/**
	 * 用户登录
	 *
	 * @param request 登录请求参数
	 * @return 返回用户实体
	 */

	@Api(path = "signIn", name = "用户登陆", author = "xwltz", createTime = "2022-06-18", needPackage = false)
	private SimpleActionResult login(LoginRequest request) {
		return memberService.memberLogin(request);
	}

	@Api(path = "logout", name = "用户退出", author = "xwltz", createTime = "2022-06-18")
	private void logout(String token) {
		StpUtil.logoutByTokenValue(token);
	}

	@Api(path = "save", name = "新增用户", author = "xwltz", createTime = "2022-06-18")
	private SimpleActionResult saveMember(MemberRequest request) {
		return memberService.memberSave(request);
	}
}
